<template>
  <svg v-on="$attrs" class="svg-icon" :class="svgClass" :style="getStyle" aria-hidden="true">
    <use :xlink:href="symbolId" :fill="props.color" />
  </svg>
</template>

<script lang="ts" setup>
  import { type CSSProperties } from 'vue';

  const props = defineProps({
    prefix: {
      type: String,
      default: 'svg-icon',
    },
    name: {
      type: String,
      required: true,
    },
    color: {
      type: String,
      default: '',
    },
    size: {
      type: [Number, String],
      default: 16,
    },
    className: {
      type: String,
      default: '',
    },
  });
  const symbolId = computed(() => `#${props.prefix}-${props.name}`);
  const svgClass = computed(() => {
    if (props.className) {
      return `svg-icon ${props.className}`;
    } else {
      return 'svg-icon';
    }
  });
  const getStyle = computed((): CSSProperties => {
    const { size } = props;
    const s = `${size}`.replace('px', '').concat('px');
    return {
      width: s,
      height: s,
    };
  });
</script>

<style lang="scss">
  .svg-icon {
    overflow: hidden;
    vertical-align: -0.15em;
    fill: currentColor;
  }
</style>
